﻿var SelectedTab;

dojo.addOnLoad(
  function () {
      hideAllPanelDef()
      unselectAllButtonDef();
      AttachEventDef();
      sistemaFaceLikeDef();
      dojo.query('input[id$="TBSelectedTab"]')[0].style.display = "none"
      SelectedTab = dojo.query('input[id$="TBSelectedTab"]')[0].value
      if (SelectedTab == 4) {
          document.getElementById("PanelDef4").style.display = "";
          document.getElementById("SelectorDef4").style.backgroundImage = "url(../Styles/Images/button98x46.png)"
      }
      else {
          if (SelectedTab == 3) {
              document.getElementById("PanelDef3").style.display = "";
              document.getElementById("SelectorDef3").style.backgroundImage = "url(../Styles/Images/button98x46.png)"
          }
          else
              if (SelectedTab == 2) {
                  document.getElementById("PanelDef2").style.display = "";
                  document.getElementById("SelectorDef2").style.backgroundImage = "url(../Styles/Images/button98x46.png)"
              }
              else {
                  document.getElementById("PanelDef1").style.display = "";
                  document.getElementById("SelectorDef1").style.backgroundImage = "url(../Styles/Images/button98x46.png)"
              }
      }
      document.getElementById("SelectorDef1").onclick = function () {
          dojo.query('input[id$="TBSelectedTab"]')[0].value = 1
          unselectAllButtonDef()
          document.getElementById("SelectorDef1").style.backgroundImage = "url(../Styles/Images/button98x46.png)"
          hideAllPanelDef()
          document.getElementById("PanelDef1").style.display = "";
          //   sistemaFaceLike();
      }
      document.getElementById("SelectorDef2").onclick = function () {
          dojo.query('input[id$="TBSelectedTab"]')[0].value = 2
          unselectAllButtonDef()
          document.getElementById("SelectorDef2").style.backgroundImage = "url(../Styles/Images/button98x46.png)"
          hideAllPanelDef()
          document.getElementById("PanelDef2").style.display = "";
          // sistemaFaceLike();
      }

      document.getElementById("SelectorDef3").onclick = function () {
          dojo.query('input[id$="TBSelectedTab"]')[0].value = 3
          unselectAllButtonDef()
          document.getElementById("SelectorDef3").style.backgroundImage = "url(../Styles/Images/button98x46.png)"
          hideAllPanelDef()
          document.getElementById("PanelDef3").style.display = "";
      }

      document.getElementById("SelectorDef4").onclick = function () {
          dojo.query('input[id$="TBSelectedTab"]')[0].value = 4
          unselectAllButtonDef()
          document.getElementById("SelectorDef4").style.backgroundImage = "url(../Styles/Images/button98x46.png)"
          hideAllPanelDef()
          document.getElementById("PanelDef4").style.display = "";
      }

      hideAllItemTemplateDef()

  })


  function sistemaFaceLikeDef() {
    dojo.query("iframe[class='fb_ltr']").forEach(function(tagElement) {
      tagElement.src= tagElement.src.replace("&width=450","") })
  }

  function unselectAllButtonDef() {
    document.getElementById("SelectorDef1").style.backgroundImage = "url(../Styles/Images/buttonGray98x46.png)"
    document.getElementById("SelectorDef2").style.backgroundImage = "url(../Styles/Images/buttonGray98x46.png)"
    document.getElementById("SelectorDef3").style.backgroundImage = "url(../Styles/Images/buttonGray98x46.png)"
    document.getElementById("SelectorDef4").style.backgroundImage = "url(../Styles/Images/buttonGray98x46.png)"
}

function hideAllPanelDef() {
    document.getElementById("PanelDef1").style.display = "none";
    document.getElementById("PanelDef2").style.display = "none";
    document.getElementById("PanelDef3").style.display = "none";
    document.getElementById("PanelDef4").style.display = "none";
}

function hideAllItemTemplateDef() {

    dojo.query("[id*='ItemTemplateDef_']").forEach(function(tagElement) {
        tagElement.style.display="none";
    });

}

function ShowHideDef(evt) {
    var divElementName = evt.currentTarget.id.replace("ImageApriDef", "ItemTemplateDef")
    dojo.query("[id='" + divElementName + "']").forEach(function(tagElement) {
        if(tagElement.style.display == "none") {
            tagElement.style.display = ""
            evt.currentTarget.childNodes[1].src = "Styles/Images/Minus.png"
           
        }
        else
        {
            tagElement.style.display = "none"
            evt.currentTarget.childNodes[1].src = "Styles/Images/Plus.png"
          
        }
    })
}

function AttachEventDef() {
    dojo.query("div[id*='ImageApriDef_']").forEach(function (tagElement) {
        dojo.connect(tagElement, "onclick", null, "ShowHide");
    });
}

function OpenEventsDef(target) {
    window.location.href = '../locali-divertimenti/Eventi.aspx?FK_Target=' + target

}